package com.design.iterator;

import java.util.List;

public class IteratorImpl<E> implements Iterator {

    private List<E> list;

    private int cursor;

    private E element;

    public IteratorImpl(E courseList) {
        this.list = (List<E>) courseList;
    }

    @Override
    public Object next() {
        System.out.print("当前位置:" + cursor + ": ");
        element = list.get(cursor);
        cursor++;
        return element;
    }

    @Override
    public boolean hasNext() {
        if (cursor > list.size() - 1) {
            return false;
        }
        return true;
    }
}
